package com.ld.hpfs.service.impl;


import java.util.ArrayList;
import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ld.hpfs.dao.UserRightsMapper;
import com.ld.hpfs.service.UserRightsService;
@Service
public class UserRightsImpl implements UserRightsService{
	private static final Logger logger = LoggerFactory.getLogger(PlanServiceImpl.class);
	
	@Autowired
	private UserRightsMapper userRightsMapper;
	
	@Override
	public ArrayList<HashMap<String,Object>> getUserRightsList(HashMap<String,Object> param){
		int count = userRightsMapper.getUserRightsListCount(param);
		if(count == 0){
			return null;
		}else{
			param.put("pageCount", count);
			if(param.get("lang").equals("en")){
			  return userRightsMapper.getUserRightsList1(param);
			}else{
			  return userRightsMapper.getUserRightsList(param);
			}
		}
	}

	
	@Override
	public int insertUserRights(HashMap<String,Object> param){
		try{
			userRightsMapper.insertUserRights(param);
			return 0;
		}catch(Exception ex){
			logger.error(ex.getMessage());
			return -1;
		}
	}
	
	@Override
	public int checkUserName(HashMap<String,Object> param){
		return userRightsMapper.checkUserName(param);
	}
	
	@Override
	public boolean checkUserRole(HashMap<String,Object> param){
		return userRightsMapper.checkUserRole(param);
	}
				
	
	@Override
	public int updateUserRights(HashMap<String,Object> param){
		try{
			int abandon = userRightsMapper.getAbandonCount(param);
			userRightsMapper.updateUserRights(param);
			if(abandon > 0){
				userRightsMapper.addAbandon(param);
			}
			return 0;
		}catch(Exception ex){
			logger.error(ex.getMessage());
			return -1;
		}
	}
	
	@Override
	public int rePassword(HashMap<String,Object> param){
		try{
			userRightsMapper.rePassword(param);
			return 0;
		}catch(Exception ex){
			logger.error(ex.getMessage());
			return -1;
		}
	}
	
	@Override
	public int freeze(HashMap<String,Object> param){
		try{
			userRightsMapper.freeze(param);
			return 0;
		}catch(Exception ex){
			logger.error(ex.getMessage());
			return -1;
		}
	}
	
	@Override
	public int unfreeze(HashMap<String,Object> param){
		try{
			userRightsMapper.unfreeze(param);
			return 0;
		}catch(Exception ex){
			logger.error(ex.getMessage());
			return -1;
		}
	}
	
	@Override
	public ArrayList<HashMap<String,Object>> getCompanyList(){
		return userRightsMapper.getCompanyList();
	}
	
	@Override
	public ArrayList<HashMap<String,Object>> getRoleList(HashMap<String,Object> param){
		if(param.get("lang").equals("en")){
			return userRightsMapper.getRoleList1();
		}else{
		    return userRightsMapper.getRoleList();
		}
	}
	@Override
	public ArrayList<HashMap<String,Object>> getPermissionTreeList(HashMap<String,Object> param){
		return userRightsMapper.getPermissionTreeList( param);
	}
	@Override
	public int setPermission(HashMap<String,Object> param){
		try{
			userRightsMapper.setPermission(param);
			return 0;
		}catch(Exception ex){
			logger.error(ex.getMessage());
			return -1;
		}
	}
	
	@Override
	public String getUserCount(HashMap<String,Object> param){
		return userRightsMapper.getUserCount(param);
	}
}
